home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 3.0 KB | 131 lines | [TEXT/CWIE] |
- // PString.cp
-
- #ifndef PString_h
- #include "PString.h"
- #endif
-
- PString::PString( Data theSpace )
- : space( theSpace )
- {
- Assert( !space.Null() );
- Assert( StorageLength() <= maxuint8 + 1 );
- Assert( Length() < StorageLength() );
- }
-
- PString::PString( Data theSpace, ConstStr255Param text )
- : space( theSpace )
- {
- Assert( !space.Null() );
- Assert( StorageLength() <= maxuint8 + 1 );
- Assert( text[0] < StorageLength() );
- if ( text != space.Start() )
- space << ConstData( text, text[0]+1 );
- }
-
- PString::PString( Data theSpace, ConstPString text )
- : space( theSpace )
- {
- Assert( !space.Null() );
- Assert( StorageLength() <= maxuint8 + 1 );
- Assert( text.Length() < StorageLength() );
- space << ConstData( text, text.Length()+1 );
- }
-
- PString::PString( Data theSpace, PString text )
- : space( theSpace )
- {
- Assert( !space.Null() );
- Assert( StorageLength() <= maxuint8 + 1 );
- Assert( text.Length() < StorageLength() );
- space << ConstData( text, text.Length()+1 );
- }
-
- PString::PString( Data theSpace, ConstData text )
- : space( theSpace )
- {
- Assert( !space.Null() );
- Assert( StorageLength() <= maxuint8 + 1 );
- Assert( text.Length() < StorageLength() );
- space[0] = TextSpace() << text;
- }
-
- void PString::Truncate( uint32 end )
- {
- if ( Length() > end )
- space[0] = end;
- }
-
- void PString::SetLength( uint32 newLength )
- {
- Assert( newLength < StorageLength() );
- space[0] = newLength;
- }
-
- void PString::operator=( ConstData text )
- {
- Assert( text.Length() < StorageLength() );
- space[0] = TextSpace() << text;
- }
-
- void PString::operator+=( uint8 c )
- {
- Assert( Length() + 1 < StorageLength() );
- if ( Length() + 1 < StorageLength() )
- space[ ++space[0] ] = c;
- }
-
- void PString::operator+=( ConstData text )
- {
- Assert( Length() + text.Length() < StorageLength() );
- space[0] += UnusedSpace() << text;
- }
-
- void PString::Remove( URange32 range )
- {
- Assert( range.End() <= Length() );
- space[0] -= range.Length();
- SpaceTail( range.Start() ) << Tail( range.End() );
- }
-
- void PString::Insert( uint32 where, uint8 c )
- {
- Assert( Length() + 1 < StorageLength() );
- Assert( where <= Length() );
-
- SpaceTail( where+1 ) << Tail( where );
- (*this)[ where ] = c;
- space[ 0 ]++;
- }
-
- void PString::Insert( uint32 where, ConstData text )
- {
- Assert( Length() + text.Length() < StorageLength() );
- Assert( where <= Length() );
-
- SpaceTail( where + text.Length() ) << Tail( where );
- SpaceTail( where ) << text;
- space[ 0 ] += text.Length();
- }
-
- void PString::Replace( URange32 range, uint8 c )
- {
- Assert( range.End() <= Length() )
- Assert( Length() - range.Length() + 1 < StorageLength() );
-
- SpaceTail( range.Start() + 1 ) << Tail( range.End() );
- (*this)[ range.Start() ] = c;
- space[ 0 ] -= range.Length();
- space[ 0 ] ++;
- }
-
- void PString::Replace( URange32 range, ConstData text )
- {
- Assert( range.End() <= Length() )
- Assert( Length() - range.Length() + text.Length() < StorageLength() );
-
- SpaceTail( range.Start() + text.Length() ) << Tail( range.End() );
- SpaceTail( range.Start() ) << text;
- space[ 0 ] -= range.Length();
- space[ 0 ] += text.Length();
- }
-